<template>
	<view class="container">
		<view class="blue-background"></view>
		<!-- 顶部蓝色区域占位（透明） -->
		<view class="header">
		</view>

		<!-- 主内容区域 -->
		<view class="main-content">
			<!-- 个人信息卡片 -->
			<view class="info-card">
				<view class="form-item">
					<text class="label">负责人:</text>
					<input class="input-field" v-model="formData.manager" placeholder="请输入负责人" />
				</view>
				<view class="form-item">
					<text class="label">身份证号码:</text>
					<input class="input-field" v-model="formData.idCard" placeholder="请输入身份证号码" />
				</view>
				<view class="form-item">
					<text class="label">手机号:</text>
					<input class="input-field" v-model="formData.phone" placeholder="请输入手机号" />
				</view>
				<view class="form-item">
					<text class="label">验证码:</text>
					<view class="code-input-wrap">
						<input class="input-field code-input" v-model="formData.code" placeholder="输入验证码" />
						<view class="divider"></view>
						<button class="get-code-btn" @click="getCode">获取验证码</button>
					</view>
				</view>
				<view class="form-item">
					<text class="label">店名:</text>
					<input class="input-field" v-model="formData.storeName" placeholder="请输入店名" />
				</view>
				<view class="form-item">
					<text class="label">工商营业执照号码:</text>
					<input class="input-field" v-model="formData.licenseNo" placeholder="请输入工商营业执照号码" />
				</view>
				<view class="form-item">
					<text class="label">经营区域:</text>
					<view class="select-field" @click="selectArea">
						<text class="select-text">{{ formData.businessArea }}</text>
						<text class="select-arrow">▼</text>
					</view>
				</view>
				<view class="form-item">
					<text class="label">地址:</text>
					<input class="input-field" v-model="formData.address" placeholder="请输入地址" />
				</view>
			</view>

			<!-- 商家简介卡片 -->
			<view class="intro-card">
				<view class="card-title">商家简介</view>
				<textarea class="intro-textarea" v-model="formData.introduction" placeholder="请输入商家简介"></textarea>
			</view>

			<!-- 身份证正反面照片卡片 -->
			<view class="photo-card">
				<view class="card-title">身份证正反面照片</view>
				<view class="photo-container">
					<view class="photo-item" v-for="(img, index) in idCardImgs" :key="index">
						<image :src="img" class="photo-preview" mode="aspectFit"></image>
						<text class="delete-text" @click="deleteImg('idCardImgs', index)">删除</text>
					</view>
					<view class="upload-placeholder" @click="uploadImg('idCardImgs')">
						<text class="upload-icon">+</text>
						<text class="upload-text">上传照片</text>
					</view>
				</view>
			</view>

			<!-- 营业执照卡片 -->
			<view class="photo-card">
				<view class="card-title">营业执照</view>
				<view class="photo-container">
					<view class="photo-item" v-for="(img, index) in licenseImgs" :key="index">
						<image :src="img" class="photo-preview" mode="aspectFit"></image>
						<text class="delete-text" @click="deleteImg('licenseImgs', index)">删除</text>
					</view>
					<view class="upload-placeholder" @click="uploadImg('licenseImgs')">
						<text class="upload-icon">+</text>
						<text class="upload-text">上传照片</text>
					</view>
				</view>
			</view>

			<!-- 门店照片卡片 -->
			<view class="photo-card">
				<view class="card-title">门店照片</view>
				<view class="photo-container">
					<view class="photo-item" v-for="(img, index) in storeImgs" :key="index">
						<image :src="img" class="photo-preview" mode="aspectFit"></image>
						<text class="delete-text" @click="deleteImg('storeImgs', index)">删除</text>
					</view>
					<view class="upload-placeholder" @click="uploadImg('storeImgs')">
						<text class="upload-icon">+</text>
						<text class="upload-text">上传照片</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部保存按钮 -->
		<view class="save-button">
			<button class="save-btn" @click="formSubmit">保存</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					manager: '张大美',
					idCard: '40365236541232563',
					phone: '18893039203',
					code: '',
					storeName: '大美汽修店',
					licenseNo: '4252336467474764646',
					businessArea: '焦作市山阳区',
					address: '山阳区迎宾路32号',
					introduction: '这里是简单的商家介绍这里是简单的商家介绍,这里是简单的商家介绍这里是简单的商家介绍,这里是简单的商家介绍这里是简单的这里是简单的商家介绍商家介绍,'
				},
				idCardImgs: ['/static/images/xtx/2fea48638742bc0be4d6d9c690e47853.png',
					'/static/images/xtx/cc07152b4a4efd345cd7c9bdffddfca1.png'
				],
				licenseImgs: ['/static/images/xtx/f9d5bbeca0344d1e62c2a903c7965232.png'],
				storeImgs: ['/static/images/xtx/73d8c12a7f90c12184af87fea40ac32c.png']
			};
		},
		methods: {
			getCode() {
				uni.showToast({
					title: '验证码已发送',
					icon: 'none'
				});
			},
			selectArea() {
				uni.showActionSheet({
					itemList: ['焦作市山阳区', '焦作市解放区', '焦作市中站区', '焦作市马村区'],
					success: (res) => {
						const areas = ['焦作市山阳区', '焦作市解放区', '焦作市中站区', '焦作市马村区'];
						this.formData.businessArea = areas[res.tapIndex];
					}
				});
			},
			formSubmit() {
				console.log('表单提交数据：', this.formData);
				uni.showToast({
					title: '保存成功',
					icon: 'success'
				});
			},
			uploadImg(type) {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						this[type].push(tempFilePaths[0]);
					}
				});
			},
			deleteImg(type, index) {
				this[type].splice(index, 1);
			}
		}
	};
</script>

<style scoped>
	.container {
		min-height: 100vh;
		background-color: #f5f5f5;
		padding-bottom: 100rpx;
		position: relative;
	}

	/* 顶部蓝色背景层（最低层） */
	.blue-background {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 300rpx;
		background: linear-gradient(120deg, #3385fd 0%, #3385fd 100%);
	}

	/* 顶部占位（透明） */
	.header {
		background-color: transparent;
		height: 170rpx;
	}

	/* 主内容区域样式（悬浮于蓝色背景上方） */
	.main-content {
		position: absolute;
		width: 690rpx;
		top: 1rpx;
		/* 约覆盖蓝色背景下沿上方20rpx */
		bottom: 140rpx;
		/* 预留给底部按钮区域 */
		z-index: 2;
		padding: 30rpx;
		overflow-y: auto;
	}

	/* 通用卡片样式 */
	.info-card,
	.intro-card,
	.photo-card {
		background-color: white;
		border-radius: 16rpx;
		padding: 40rpx 20rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
	}

	/* 表单项目样式 */
	.form-item {
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.form-item:last-child {
		margin-bottom: 0;
	}

	.label {
		color: #333;
		font-size: 28rpx;
		width: 240rpx;
		flex-shrink: 0;
		font-weight: bold;
		white-space: nowrap;
	}

	.input-field {
		flex: 1;
		height: 60rpx;
		background-color: #ffffff;
		border: 2rpx solid #ebebeb;
		border-radius: 28rpx;
		padding: 0 20rpx;
		font-size: 28rpx;
		color: #333;
	}

	.code-input-wrap {
		flex: 1;
		display: flex;
		align-items: center;
		background-color: #ffffff;
		border: 2rpx solid #e0e0e0;
		border-radius: 28rpx;
		height: 60rpx;
	}

	.code-input {
		flex: 1;
		border: none;
		background: transparent;
		padding: 0 20rpx;
	}

	.divider {
		width: 2rpx;
		height: 40rpx;
		background-color: #e0e0e0;
	}

	.get-code-btn {
		background-color: #ffffff;
		color: #007AFF;
		border: none;
		padding: 0 20rpx;
		height: 60rpx;
		font-size: 24rpx;
		border-radius: 28rpx 28rpx 28rpx 28rpx;
	}

	.select-field {
		flex: 1;
		height: 60rpx;
		background-color: #ffffff;
		border: 2rpx solid #e0e0e0;
		border-radius: 28rpx;
		padding: 0 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		cursor: pointer;
	}

	.select-text {
		font-size: 28rpx;
		color: #333;
	}

	.select-arrow {
		font-size: 24rpx;
		color: #999;
	}

	/* 卡片标题样式 */
	.card-title {
		color: #333;
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 30rpx;
	}

	/* 商家简介样式 */
	.intro-textarea {
		width: 92%;
		height: 160rpx;
		background-color: #ffffff;
		border: 2rpx solid #e0e0e0;
		border-radius: 24rpx;
		padding: 20rpx;
		font-size: 28rpx;
		color: #333;
		line-height: 1.5;
	}

	/* 照片容器样式 */
	.photo-container {
		display: flex;
		flex-wrap: wrap;
		gap: 16rpx;
	}

	.photo-item {
		position: relative;
	}

	.photo-preview {
		width: 150rpx;
		height: 150rpx;
		border-radius: 8rpx;
		border: 2rpx solid #e0e0e0;
	}

	.delete-text {
		position: absolute;
		top: 100%;
		left: 50%;
		transform: translateX(-50%);
		margin-top: 6rpx;
		color: #999;
		font-size: 24rpx;
	}

	.upload-placeholder {
		width: 150rpx;
		height: 150rpx;
		border: 2rpx dashed #ccc;
		border-radius: 8rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #fafafa;
	}

	.upload-icon {
		font-size: 60rpx;
		color: #999;
		margin-bottom: 10rpx;
	}

	.upload-text {
		font-size: 24rpx;
		color: #999;
	}

	/* 底部保存按钮样式 */
	.save-button {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 30rpx;
		background-color: white;
		border-top: 1rpx solid #e0e0e0;
		z-index: 3;
		/* 置于最上方 */
	}

	.save-btn {
		width: 100%;
		height: 88rpx;
		background-color: #007AFF;
		color: white;
		font-size: 32rpx;
		font-weight: bold;
		border-radius: 44rpx;
		border: none;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.save-btn:active {
		background-color: #0056CC;
	}
</style>